'''
Created on Jul 13, 2010

@author: Behrooz Nobakht
'''
from amscms import settings
from django.core.paginator import Paginator
from amscms.core.templatetags.digg_paginator import digg_paginator

def create_pagination_context(object_list, base_url, page=1):
    page_size=settings.PAGING_PAGE_SIZE
    pages = Paginator(object_list, per_page=page_size)
    context = {}
    context["current_page"] = pages.page(page)
    context["page"] = int(page)
    context["pages"] = pages.num_pages
    context["results_per_page"] = page_size
    context["base_url"] =  base_url
    context["previous"] = pages.page(page).previous_page_number()
    context["has_previous"] = pages.page(page).has_previous()
    context["next"] = pages.page(page).next_page_number()
    context["has_next"] = pages.page(page).has_next()
    context["is_paginated"] = True
    
    paged = digg_paginator(context)
    context.update(paged)
    
    return pages, context

def jsonify_pagination_context(pctx):
    newctx = digg_paginator(pctx)
    if newctx.has_key('current_page'):
        del newctx['current_page']
    return newctx
